// utils/fileSize.ts

/**
 * Converts the given file size to a human-readable format.
 * 
 * @param bytes The file size in bytes.
 * @returns A string representing the file size with the appropriate unit (B, KB, MB, GB).
 */
export function formatFileSize(bytes: number): string {
    if (bytes === 0) return '0 B';
    const k = 1024;
    const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
}